function addMarker(latitude,longitude, description) {
	var marker = new GMarker(new GLatLng(latitude, longitude));
	GEvent.addListener(marker, 'click',
		function() {
			marker.openInfoWindowHtml(description);
			//marker.showMapBlowup({"zoomLevel":18,"mapType":G_SATELLITE_MAP});
		}
	);
	map.addOverlay(marker);
}

//-------------------------------------------------------
//-------------------------------------------------------
function createMarker(lat, lng, html, iconImage, title) {
	var marker;
	if(iconImage !=''){
		var icon = new GIcon();
		icon.image = iconImage;
		icon.iconSize = new GSize(37, 32);
		icon.iconAnchor = new GPoint(16, 32);
		icon.infoWindowAnchor  = new GPoint(16, 32);
		marker = new GMarker(new GLatLng(lat, lng), {"title":title, "icon":icon});
	} else {
		marker = new GMarker(new GLatLng(lat, lng), {"title":title});
	}
	//GEvent.addListener(marker, 'click', function() {
	GEvent.addListener(marker, 'mouseover', function() {
		var markerHTML = html;
		marker.openInfoWindowHtml(markerHTML);
	});
	return marker;
}

/**
 *
 **/
function find_street(item){
	$.ajax({
		type:"get",
		url: "<?php echo base_url(); ?>calles/nombre/"+item,
		//data:{'item': item},
		success: function(rsp) {
		  var marker = rsp.documentElement;
		  var name = marker.getAttribute('name');
			if (name == item){
			  var lat = marker.getAttribute('lat');
			  var lng = marker.getAttribute('lng');
			  name = item.replace(/-/g, ' ');
			  if ((lat == "") || (lng == "") ){
				text = "<p class='comment'>Podes ayudarnos a encontrar la Calle <strong>"+name+"</strong> a traves de: </p>";
				create_dialog(text);
			  }else{				
				var markermap = new GMarker(new GLatLng(lat, lng), {"title":name});
				map.addOverlay(markermap);
				map.panTo(new GLatLng(lat, lng));
				//add the points if exists
				var points = marker.getElementsByTagName('point');
				if(points.length > 0){
					var source, dest, distance;
					var polyPoints = new Array();
					for(var j=0; j<points.length; j++){
						lat = points[j].getAttribute('lat');
						lng = points[j].getAttribute('lng');			
						polyPoints.push(new GLatLng(lat, lng));
						
						//calculations
						if(j>0){
							source = new LatLon(parseFloat(polyPoints[j-1].lat()),parseFloat(polyPoints[j-1].lng()));
							dest = new LatLon(parseFloat(polyPoints[j].lat()),parseFloat(polyPoints[j].lng()));
							distance += source.distanceTo(dest, 2) * 1000;							
						}else{
							distance = 0;
						}
					}
					var polyline = new GPolyline(polyPoints,"#BF0A2B", 9);
					map.addOverlay(polyline);
					
					var scale = "m";
					var txt = '<div id="distance" align="center" class="centered ui-state-highlight"><p>Longitud aproximada de <strong>'+name+'</strong>: '+distance+' '+scale+'.</p></div>';
					$('#distance').replaceWith(txt).fadeIn(8000);
					$('#distance').mouseout(function(){$(this).fadeOut(5000);});					
				} else{
					$("#distance").fadeOut("fast");
				}
			  }
			  return;
			}
		}
	});
}

function find_pharmacie(item){
	$.ajax({
		type:"get",
		url: "<?php echo base_url(); ?>farmacias/name/"+item,
        //data:{'item': item},
		success: function(rsp) {			
		  var marker = rsp.documentElement;
		  var name = marker.getAttribute('name');
			if (name == item){
			  var lat = marker.getAttribute('lat');
			  var lng = marker.getAttribute('lng');
			  name = item.replace(/-/g, ' ');
			  if ((lat == "") || (lng == "") ){
				text = "<p class='comment'>Podes ayudarnos a encontrar la Farmacia <strong>"+name+"</strong> a traves de: </p>";
				create_dialog(text);
			  }else{				
				var add = marker.getElementsByTagName('add')[0].firstChild.nodeValue;				
				var imgTag = marker.getElementsByTagName('img');
				var img = "";
				if(imgTag[0] != undefined && imgTag[0].childNodes.length > 0){
					img = imgTag[0].firstChild.nodeValue;
				}
				var html = write_html("farmacias",item, name, img, add, "");
				//update the map
				//create a new marker and add its info window
        var iconImage = marker.getElementsByTagName('icon')[0].firstChild.nodeValue;
				var markermap = createMarker(lat, lng, html, iconImage, name);
				map.addOverlay(markermap);
				map.panTo(new GLatLng(lat, lng));	
				markermap.openInfoWindowHtml(html);
        show_distance('Farmacia '+name, lat, lng);
			  }
			  return;
			}
		}
	});
}

function find_goout(item){
	$.ajax({
		type:"get",
        url:"<?php echo base_url(); ?>salidas/name/"+item,
		//data:{'item': item},
		success: function(rsp){					
		  var marker = rsp.documentElement;
		  var name = marker.getAttribute('name');
		  var lat = marker.getAttribute('lat');
		  var lng = marker.getAttribute('lng');

		  /*
		  var name = marker.getElementsByTagName('id')[0].firstChild.nodeValue;
		  var lat = marker.getElementsByTagName('lat')[0].firstChild.nodeValue;
		  var lng = marker.getElementsByTagName('lng')[0].firstChild.nodeValue;
		  */
		  name = item.replace(/-/g, ' ');
		  if ((lat == "") || (lng == "") ){
				text = "<p class='comment'>Podes ayudarnos a localizar <strong>"+name+"</strong> a traves de: </p>";
			create_dialog(text);
		  }else{		        
			//var add = marker.getElementsByTagName('address')[0].firstChild.nodeValue;
			var add = marker.getElementsByTagName('add')[0].firstChild.nodeValue;
			var imgTag = marker.getElementsByTagName('img');
			var img = "";
			if(imgTag[0] != undefined && imgTag[0].childNodes.length > 0){
				img = imgTag[0].firstChild.nodeValue;
			}
			var html = write_html("salidas",item, name, img, add, "");
			//update the map
			//create a new marker and add its info window
			var iconImage = marker.getElementsByTagName('icon')[0].firstChild.nodeValue;
			var markermap = createMarker(lat, lng, html, iconImage, name);
			map.addOverlay(markermap);
			map.panTo(new GLatLng(lat, lng));
			markermap.openInfoWindowHtml(html);
      show_distance(name, lat, lng);
		  }
		  return;
  		}
	});
}

function find_green(item){
	$.ajax({
		type:"get",
		dataType:"xml",
		url:'<?php echo base_url(); ?>plazas/name/'+item,
		//data:{'item': item},
		success: function(rsp){
		  var marker = rsp.documentElement;
		  var name = marker.getAttribute('name');
			if (name == item){
			  var lat = marker.getAttribute('lat');
			  var lng = marker.getAttribute('lng');
			  name = item.replace(/-/g, ' ');
			  if ((lat == "") || (lng == "") ){
				text = '<p class="comment">Podes ayudarnos a encontrar el Parque/Plaza <strong>'+name+'</strong> a traves de: </p>';
				create_dialog(text);
			  }else{				
				var add = marker.getElementsByTagName('add')[0].firstChild.nodeValue;
				var desc='';
				var desc_tag = marker.getElementsByTagName('desc');
				for(var j=0; j < desc_tag.length; j++){
				  desc += '<p class="comment">'+desc_tag[j].firstChild.nodeValue+'</p>';
				}
				var img = marker.getElementsByTagName('img')[0].firstChild.nodeValue;
				var html = write_html("plazas",item,name, img, add, desc);
				//update the map
				//create a new marker and add its info window
        var iconImage = marker.getElementsByTagName('icon')[0].firstChild.nodeValue;
				var markermap = createMarker(lat, lng, html, iconImage, name);
				map.addOverlay(markermap);
				map.panTo(new GLatLng(lat, lng));
				markermap.openInfoWindowHtml(html);
        show_distance(name, lat, lng);
			  }
			  return;
			}		  		  
  		}
	});
}

function find_important(item){
	$.ajax({
		type:"get",
		url:'<?php echo base_url(); ?>interes/name/'+item,
		//data:{'item': item},
		success: function(rsp){
		  var marker = rsp.documentElement;
		  var name = marker.getAttribute('name');
		    if (name == item){
		      var lat = marker.getAttribute('lat');
		      var lng = marker.getAttribute('lng');
			  name = item.replace(/-/g, ' ');
		      if ((lat == "") || (lng == "") ){
				text = "<p class='comment'>Podes ayudarnos a encontrar <strong>"+name+"</strong> a traves de: </p>";
		        create_dialog(text);
		      }else{		        
		        var add = marker.getElementsByTagName('add')[0].firstChild.nodeValue;
				var desc='';
				var desc_tag = marker.getElementsByTagName('desc');				
				for(var j=0; j < desc_tag.length; j++){
					if(desc_tag[j].childNodes.length > 0){
						desc += '<p class="lheader comment">'+desc_tag[j].firstChild.nodeValue+'</p>';
					}
				}
				var imgTag = marker.getElementsByTagName('img');
				var img = "";
				if(imgTag[0] != undefined && imgTag[0].childNodes.length > 0){
					img = imgTag[0].firstChild.nodeValue;
				}				
				var html = write_html("interes",item,name, img, add, desc);
		        //update the map
		        //create a new marker and add its info window
		        var iconImage = marker.getElementsByTagName('icon')[0].firstChild.nodeValue;
		        var markermap = createMarker(lat, lng, html, iconImage, name);
		        map.addOverlay(markermap);
                        map.panTo(new GLatLng(lat, lng));
                        markermap.openInfoWindowHtml(html);

                        show_distance(name, lat, lng);
		      }
		      return;
		    }
		}
	}); 
}

function find_evento(item){
  item = item.replace(/_/g, '-');
	$.ajax({
		type:"get",
		url:"<?php echo base_url(); ?>eventos/name/"+item,
		//data:{'item': item},
		success: function(rsp){
		  var marker = rsp.documentElement;
		  var name = marker.getAttribute('name');
		    if (name == item){
		      var lat = marker.getAttribute('lat');
		      var lng = marker.getAttribute('lng');
			  name = item.replace(/-/g, ' ');
		      if ((lat == "") || (lng == "") ){
				text = "<p class='comment'>Podes ayudarnos a encontrar el evento <strong>"+name+"</strong> a traves de: </p>";
		        create_dialog(text);
		      }else{		        
		        var add = marker.getElementsByTagName('add')[0].firstChild.nodeValue;
		        var desc='';
		        var desc_tag = marker.getElementsByTagName('desc');
		        for(var j=0; j < desc_tag.length; j++){
		          desc += '<p class="comment">'+desc_tag[j].firstChild.nodeValue+'<p/>';
		        }		
		        var img = marker.getElementsByTagName('img')[0].firstChild.nodeValue;
			var html = write_html("eventos",item,name, img, add, desc);
		        //update the map
		        //create a new marker and add its info window
		        var iconImage = marker.getElementsByTagName('icon')[0].firstChild.nodeValue;
		        var markermap = createMarker(lat, lng, html, iconImage, name);
		        map.addOverlay(markermap);
                        map.panTo(new GLatLng(lat, lng));
                        markermap.openInfoWindowHtml(html);
		      }
		    }
		}
	});  
}

function find_sport(item){
	$.ajax({
		type:"get",
		url:"<?php echo base_url(); ?>deporte/name/"+item,
		//data:{'item': item},
		success: function(rsp){
		  var marker = rsp.documentElement;
		  var name = marker.getAttribute('name');
		    if (name == item){
		      var lat = marker.getAttribute('lat');
		      var lng = marker.getAttribute('lng');
			  name = item.replace(/-/g, ' ');
		      if ((lat == "") || (lng == "") ){
				text = "<p class='comment'>Podes ayudarnos a encontrar <strong>"+name+"</strong> a traves de: </p>";
		        create_dialog(text);
		      }else{
		        var add = marker.getElementsByTagName('add')[0].firstChild.nodeValue;
		        var desc='';
		        var desc_tag = marker.getElementsByTagName('desc');
		        for(var j=0; j < desc_tag.length; j++){
                            if(desc_tag[j].childNodes.length > 0){
                                desc += '<p class="comment">'+desc_tag[j].firstChild.nodeValue+'<p/>';
                            }
		        }

				var imgTag = marker.getElementsByTagName('img');
				var img = "";
				if(imgTag[0] != undefined && imgTag[0].childNodes.length > 0){
						img = imgTag[0].firstChild.nodeValue;
				}
			var html = write_html("deporte",item,name, img, add, desc);
		        //update the map
		        //create a new marker and add its info window
		        var iconImage = marker.getElementsByTagName('icon')[0].firstChild.nodeValue;
		        var markermap = createMarker(lat, lng, html, iconImage, name);
		        map.addOverlay(markermap);
                        map.panTo(new GLatLng(lat, lng));
                        markermap.openInfoWindowHtml(html);

                        show_distance(name, lat, lng);
		      }
		    }
		}
	});
}

function find_trend(value){
	$.ajax({
		type:'get',
		url:'http://search.twitter.com/search.json',
		data:{'q':'%23'+value},
		success: function(rsp){
			console.debug(rsp);
		}
	});
}

function find_all_goout(){
	$.ajax({
                type: "get",
                url:"<?php echo base_url(); ?>salidas/all/",
                success: function(rsp){
                        var markers = rsp.getElementsByTagName('marker');
                        var cant = markers.length;
                        var markermap,lat,lng,html,name,iconImage,add,imgTag,img,item;
                        var bounds = new GLatLngBounds();
                        for(i=0; i < cant; i++){
                                item = markers[i].getAttribute('name');
                                name = item.replace(/-/g, ' ');
                                lat = markers[i].getAttribute('lat');
                                lng = markers[i].getAttribute('lng');
                                add = markers[i].getElementsByTagName('add')[0].firstChild.nodeValue;
								
								imgTag = markers[i].getElementsByTagName('img');
								img = "";
								if(imgTag[0] != undefined && imgTag[0].childNodes.length > 0){
										img = imgTag[0].firstChild.nodeValue;
								}						
                                html = write_html("salidas",item,name, img, add, "");
                                //update the map
                                //create a new marker and add its info window
                                iconImage = markers[i].getElementsByTagName('icon')[0].firstChild.nodeValue;
                                markermap = createMarker(lat, lng, html, iconImage, name);
                                map.addOverlay(markermap);
                                //add the marker to the bounds
                                bounds.extend(markermap.getPoint());
                                //setInterval("markermap.openInfoWindowHtml(html)", 3000);
                        }
                        //set the center using BOUNDS
                        var center = bounds.getCenter();
                        var zoom = map.getBoundsZoomLevel(bounds);
                        map.setCenter(center,zoom);
                }
		});
}

function find_all_importants(){
	$.ajax({
			type: "get",
			url:"<?php echo base_url(); ?>interes/all",
			success: function(rsp){
				var markers = rsp.getElementsByTagName('marker');
				var markermap,lat,lng,html,name,iconImage,add,imgTag,img,item;
				var bounds = new GLatLngBounds();
				for(i=0; i < markers.length; i++){
                                        item = markers[i].getAttribute('name');
					name = item.replace(/-/g, ' ');
					lat = markers[i].getAttribute('lat');
					lng = markers[i].getAttribute('lng');
					add = markers[i].getElementsByTagName('add')[0].firstChild.nodeValue;
					imgTag = markers[i].getElementsByTagName('img');
					img = "";
					if(imgTag[0] != undefined && imgTag[0].childNodes.length > 0){
							img = imgTag[0].firstChild.nodeValue;
					}		
					var desc='';
					var desc_tag = markers[i].getElementsByTagName('desc');	
					for(var j=0; j < desc_tag.length; j++){
						if(desc_tag[j].childNodes.length > 0){
							desc += '<p class="lheader comment">'+desc_tag[j].firstChild.nodeValue+'</p>';
						}
					}							
					html = write_html("interes",item,name, img, add, desc);
					//update the map
					//create a new marker and add its info window
					iconImage = markers[i].getElementsByTagName('icon')[0].firstChild.nodeValue;	
					markermap = createMarker(lat, lng, html, iconImage, name);
					map.addOverlay(markermap);
					//add the marker to the bounds
					bounds.extend(markermap.getPoint());
				}
				//set the center using BOUNDS
				var center = bounds.getCenter();
				var zoom = map.getBoundsZoomLevel(bounds);
				map.setCenter(center,zoom);
			}
		});
}

function get_contextual_markers(){
	var fecha = new Date();
	var day = fecha.getDay();
	if(day == 0 || day >= 4){
		find_all_goout();
	} else {
		find_all_importants();
	}
}

function find_all_pharmacies(){
	$.ajax({
			type: "get",
			url:"<?php echo base_url(); ?>farmacias/all/",
			success: function(rsp){
				var markers = rsp.getElementsByTagName('marker');
				var markermap,lat,lng,html,name,iconImage,add,imgTag,img,item;
				var bounds = new GLatLngBounds();
				for(i=0; i < markers.length; i++){
                                        item = markers[i].getAttribute('name');
					name = item.replace(/-/g, ' ');
					lat = markers[i].getAttribute('lat');
					lng = markers[i].getAttribute('lng');
					add = markers[i].getElementsByTagName('add')[0].firstChild.nodeValue;
					imgTag = markers[i].getElementsByTagName('img');
					img = "";
					if(imgTag[0] != undefined && imgTag[0].childNodes.length > 0){
							img = imgTag[0].firstChild.nodeValue;
					}		
					html = write_html("farmacias",item,name, img, add, "");
					//update the map
					//create a new marker and add its info window
          iconImage = markers[i].getElementsByTagName('icon')[0].firstChild.nodeValue;
					markermap = createMarker(lat, lng, html, iconImage, name);
					map.addOverlay(markermap);
					//add the marker to the bounds
					bounds.extend(markermap.getPoint());
				}
				//set the center using BOUNDS
				var center = bounds.getCenter();
				var zoom = map.getBoundsZoomLevel(bounds);
				map.setCenter(center,zoom);
			}
		});
}

function find_all_events(){
	$.ajax({
		type:"get",
		url:"<?php echo base_url(); ?>eventos/todos/",
		success: function(data){
		  var markers = data.documentElement.children;
		  var cant = markers.length;
		  var name;
		  for (var i = 0; i < cant; i++) {
		    name = markers[i].getAttribute('name');
			  var lat = markers[i].getAttribute('lat');
			  var lng = markers[i].getAttribute('lng');
				name = item.replace(/-/g, ' ');
				var add = markers[i].getElementsByTagName('add')[0].firstChild.nodeValue;
				var desc='';
				var desc_tag = markers[i].getElementsByTagName('desc');
				for(var j=0; j < desc_tag.length; j++){
				  desc += '<p class="comment">'+desc_tag[j].firstChild.nodeValue+'<p/>';
				}
				var img = markers[i].getElementsByTagName('img')[0].firstChild.nodeValue;
				var html="<table><tbody>"+
						"<tr><td><h2><strong>"+name+"</strong></h2></td></tr>"+
						"<tr><td>"+
							"<ul><li>"+add+"</li><li>"+desc+"</li></ul></td></tr>"+
						"<tr><td align='center'><img class='map_img' src='"+img+"'/></td></tr>"+
						"</tbody></table>";

				//update the map
				//create a new marker and add its info window
				var iconImage = markers[i].getElementsByTagName('icon')[0].firstChild.nodeValue;
				var marker = createMarker(lat, lng, html, iconImage, name);
				map.addOverlay(marker);
				map.panTo(new GLatLng(lat, lng));
				marker.openInfoWindowHtml(html);
			  }
	  }
	});
}

function write_html(cat,item, name, img, add, desc){
  img = (img!="")?"<img class='lheader map_img' src='"+img+"'/>":"";
	var html="<div class='map_info'>"+
				"<div>"+
				 "<h3 class='ui-state-default'><strong>"+name+"</strong></h3>"+
				 img+"<p>"+add+"</p>"+desc+				
				 "<div class='addthis_toolbox addthis_default_style' style='padding-top:5px'>"+
					"<a href='http://addthis.com/bookmark.php?v=250&amp;username=xa-4c29e8ec5e14924f' class='addthis_button_compact comment'"+
						"addthis:url='<?php echo base_url(); ?>"+cat+"/nombre"+item+"'"+
						"addthis:title= Punta Alta '"+name+"': '"+add+" @conocepunta>Compartilo<\/a>"+
					"<span class='addthis_separator'>|</span>"+
					"<a class='addthis_button_facebook'"+
						"addthis:url='<?php echo base_url(); ?>"+cat+"/nombre"+item+"'"+
						"addthis:title= #PuntaAlta '"+name+": "+add+" @conocepunta'><\/a>"+
					"<a class='addthis_button_myspace'"+
						"addthis:url='<?php echo base_url(); ?>"+cat+"/nombre"+item+"'"+
						"addthis:title= Punta Alta '"+name+": "+add+" @conocepunta'><\/a>"+
					"<a class='addthis_button_google'"+
						"addthis:url='<?php echo base_url(); ?>"+cat+"/nombre"+item+"'"+
						"addthis:title= Punta Alta '"+name+": "+add+" @conocepunta'><\/a>"+
					"<a class='addthis_button_twitter'"+
						"addthis:url='<?php echo base_url(); ?>"+cat+"/nombre"+item+"'"+
						"addthis:title= #PuntaAlta '"+name+": "+add+" @conocepunta'><\/a>"+
				"<\/div>"+
				"<\/div>"+
				//'<div><iframe src="http://www.facebook.com/plugins/like.php?href=www.conocepunta.com.ar/%23'+item+' show_faces="true" action="like" scrolling="no" frameborder="0" style="height: 60px; width: 220px" allowTransparency="true"></iframe></div>'+				
				'<div><iframe src="http://www.facebook.com/plugins/like.php?href=www.conocepunta.com.ar/'+cat+'/nombre/'+item+'" layout="button_count" show_faces="false" action="like" scrolling="yes" frameborder="0" style="height: 60px; width: 220px" allowTransparency="false"></iframe></div>'+
				//'<div><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.conocepunta.com.ar%2F%23'+item+'" layout="button_count" show_faces="false" action="like" scrolling="yes" frameborder="0" style="height: 60px; width: 220px" allowTransparency="false"></iframe></div>'+												
			 "</div>";
	return html;
}

function show_me(){
    if(navigator.geolocation){
        navigator.geolocation.getCurrentPosition(function(position){
            var lat = position.coords.latitude;
            var lng = position.coords.longitude;
            var html = "<p>Gracias por la buena onda!</p>";
            var iconImage = "";
            var name ="Me encuentro aqui";
            var markermap = createMarker(lat, lng, html, iconImage, name);
            map.addOverlay(markermap);
            map.panTo(new GLatLng(lat, lng));
            markermap.openInfoWindowHtml(html);
        });
    } else{
        var text = "<p class='comment'>Tu navegador no soporta esta funcionalidad.</p><p class='comment'>Actualizalo!!!</p>";
        create_dialog(text);
    }
}

function load_panoramio(){
    //panoramio layer
    var panoLayer = new GLayer("com.panoramio.all");
    map.addOverlay(panoLayer);
}

function show_distance(item, slat, slng){
    var source = new LatLon(parseFloat(slat),parseFloat(slng));
    var dest = new LatLon(parseFloat(-38.880430824937385),parseFloat(-62.0748777688641));   //distance to central park
    var distance = source.distanceTo(dest, 2);    
    //in hours
    var walk_time = distance / 3.5;
    var wht = Math.floor(walk_time);
    var wht_text = (wht > 0) ? (wht+" hr") : "";
    var wmt = Math.floor(((walk_time - wht) * 60));
    //var wst = Math.floor((((walk_time - wht) * 60) - wmt) * 60);

    var car_time = distance / 10;
    var cht = Math.floor(car_time);
    var cht_text = (cht > 0) ? (cht+" hr") : "";    
    var cmt = Math.floor(((car_time - cht) * 60));
    //var cst = Math.floor((((car_time - cht) * 60) - cmt) * 60);
	
    var scale = "km";
    if(distance < 1){
        distance = distance * 1000;
        scale = "m";
    }
    var txt = '<div id="distance" align="center" class="centered ui-state-highlight"><p>Distancia desde <strong>'+item+'</strong> hasta la <strong>Plaza Belgrano</strong>: '+distance+' '+scale+'.</p>'+
              '<p><strong>Caminando</strong>: '+wht_text+' '+wmt+' min.</p><p>En <strong>vehiculo</strong>: '+cht_text+' '+cmt+' min.</p>'+
              '<h4>Todos los datos son aproximados.</h4></div>';
    $('#distance').replaceWith(txt);
    $('#distance').fadeIn(8000);
    $('#distance').show(15000);
    $('#distance').mouseout(function(){$(this).fadeOut(5000);});

    return txt;
}

$(function(){
  $.getJSON("<?php echo base_url(); ?>estadisticas/get_stats/", function(data){
    $.each(data, function(i, val) {
      var content;
      if(val > 0.1){
        content = "<span class='high_rate rheader'></span>";
      }else if(val >= 0.025){
        content = "<span class='mid_rate rheader'></span>";
      }else{
        content = "<span class='low_rate rheader'></span>";
      }
      $("#" + i).append(content);
    });
  });
});

/*
function view_tour(){
	var timer = setInterval(get_tour, 3000);
	//iteramos sobre el cjto del tour actual y creamos 
}
*/